package com.ihr360.payroll.dao;


import com.ihr360.payroll.model.dto.attendance.plan.AttendancePlan;
import com.ihr360.rest.reposity.SimpleRestReposity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

/**
 * @author tomtao
 */
@RepositoryRestResource
public interface AttendancePlanRepository extends SimpleRestReposity<AttendancePlan, Long> {

    List<AttendancePlan> findByCompanyId(String companyId);

    List<AttendancePlan> findByIsSystemTemplate(boolean isSystemTemplate);

    List<AttendancePlan> findByPayrollConfigId(Long payrollConfigId);

    int countByPayrollConfigId(Long payrollConfigId);

    int countByEnabledAndPayrollConfigId(boolean enabled, Long payrollConfigId);

    int countByCompanyIdAndNameAndIdNot(String companyId, String name, Long id);

    int countByIsSystemTemplateAndNameAndIdNot(boolean isSystemTemplate, String name, Long id);

    int countByCompanyIdAndName(String companyId, String name);

    int countByIsSystemTemplateAndName(boolean isSystemTemplate, String name);

    @Modifying
    @Query(nativeQuery = true, value = "delete from PersonalLeaveRule_referenceFields where referenceFields_id in (:fieldIds)")
    Integer deletePersonalLeaveRuleReferenceFields(@Param("fieldIds") List<Long> fieldIds);

    @Modifying
    @Query(nativeQuery = true, value = "delete from OvertimeRule_referenceFields where referenceFields_id in (:fieldIds)")
    Integer deleteOvertimeRuleReferenceFields(@Param("fieldIds") List<Long> fieldIds);

    @Modifying
    @Query(nativeQuery = true, value = "delete from EnrollAdjustRule_referenceFields where referenceFields_id in (:fieldIds)")
    Integer deleteEnrollAdjustRuleReferenceFields(@Param("fieldIds") List<Long> fieldIds);

    @Modifying
    @Query(nativeQuery = true, value = "delete from SickLeaveRule_referenceFields where referenceFields_id in (:fieldIds)")
    Integer deleteSickLeaveRuleReferenceFields(@Param("fieldIds") List<Long> fieldIds);

    @Modifying
    @Query(nativeQuery = true, value = "delete from SyntheticalOvertimerule_referencefields where referenceFields_id in (:fieldIds)")
    Integer deleteSyntheticalOvertimeruleReferenceFields(@Param("fieldIds") List<Long> fieldIds);


}